﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using KinectDwa;
using System.Windows.Threading;

namespace Kinect.Tests
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static Border Layout;

        public MainWindow()
        {
            InitializeComponent();

            Layout = LayoutRoot;

            this.Closed += new EventHandler(MainWindow_Closed);
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);

            KinectHandler.KinectReady += new EventHandler(KinectHandler_KinectReady);
            KinectHandler.Failed += new EventHandler(KinectHandler_Failed);

            this.WindowState = System.Windows.WindowState.Maximized;
            this.ResizeMode = System.Windows.ResizeMode.NoResize;
            this.WindowStyle = System.Windows.WindowStyle.None;
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            KinectHandler.Initialize();
        }

        void KinectHandler_KinectReady(object sender, EventArgs e)
        {
            chooser.btnContinue.Visibility = Visibility.Visible;
            chooser.btnContinue.Tag = "Continue";
            chooser.txtInfo.Text = "Kinect ready!";
        }

        void KinectHandler_Failed(object sender, EventArgs e)
        {
            chooser.btnContinue.Visibility = Visibility.Visible;
            chooser.btnContinue.Tag = "Test anyway...";
            chooser.txtInfo.Text = "Kinect init failed: " + sender.ToString();
        }

        void MainWindow_Closed(object sender, EventArgs e)
        {
            KinectHandler.UninitializeKinectService();
        }

        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (StaticTestEngine.Sticky == true)
            {
                StickyButtonHandler.Click();
            }
            else
            {
                //click into oblivion, nothing here
                StaticTestEngine.AddClickMarker(System.Windows.Forms.Cursor.Position, false, "");
            }
        }


    }
}
